import Addition from "@/components/Addition";
import QueryUserDefine from "@/components/QueryUserDefine";
import { s_getcommontableinfo, s_getPurchaseInfo, s_getSelectData, s_getTableInfo, s_operateInfo, s_purchase_updateInfo, s_updateInfo, state2text, status2text } from "@/services/basis";
import { ActionType, EditableFormInstance, EditableProTable, ProCard, ProColumns, ProForm, ProFormDatePicker, ProFormInstance, ProFormRadio, ProFormSelect, ProFormText, ProFormTextArea, ProTable, Search } from "@ant-design/pro-components"
import { Button, Image,Col, message, Modal, Row, Space, Typography } from "antd";
import { useEffect, useRef, useState } from "react";
import { getSelection } from "@/services/selections";
import moment from "moment";
import QueryVendor from "@/components/QueryVendor";
import QueryMaterial2 from "@/components/QueryMaterial2";
import { Item } from "rc-menu";
import { useModel } from "@umijs/max";

const App:React.FC=()=>{
  const [open,setOpen]=useState(false);
  const [etype,setEtype]=useState(1);
  const [otype,setOtype]=useState(1);
  const [dataSource,setDataSource]=useState<DataType2[]>([]);
  const [dataPrint,setDataPrint]=useState([]);
  const [selectedRecord,setSelectedRecord]=useState<DataType[]>([]);

  const [material,setMaterial]=useState<{id:any,code:any,name:any,invstd:any,invstd2:any,munit_name:any}[]>([]);
  const [vendor,setVendor]=useState<{id:any,name:any,salecategory2:any}[]>([]);
  const [userdefine,setUserDefine]=useState<{uid:any,uname:any,vlabel:any,value:any}[]>([]);
  const [material_id,setMaterial_id]=useState(0);
  const [rowno,setRowno]=useState(0); 
  const [addition,setAddition]=useState([]);
  const [vouchCode,setVouchCode]=useState('');

  const mtable_ref=useRef<ActionType>();
  const mform_ref=useRef<ProFormInstance>();
  const mtable2_ref=useRef<ActionType>();
  const editorFormRef=useRef<EditableFormInstance>();

  const [openSale,setOpenSale]=useState(false);
  const formRef_sale=useRef<ProFormInstance>();
  const editableRef_sale=useRef<EditableFormInstance>();
  const actionRef_sale=useRef<ActionType>();
  const [saleRecords,setSaleRecords]=useState([]);

  const [openAlloc,setOpenAlloc]=useState(false);
  const editableRef_alloc=useRef<EditableFormInstance>();
  const actionRef_alloc=useRef<ActionType>();
  const [allocRecords,setAllocRecords]=useState<any[]>([]);
  const formRef_alloc=useRef<ProFormInstance>();
  const [total,setTotal]=useState(0);

  const [openPrint,setOpenPrint]=useState(false);
  const { initialState, setInitialState } = useModel('@@initialState');
  const [selectedLineKeys,setSelectedLineKeys]=useState<any[]>([]);
  const [selectedLineKeys2,setSelectedLineKeys2]=useState<any[]>([]);

  useEffect(()=>{
    if(vendor.length>0){
      const v=vendor[0];
      mform_ref.current?.setFieldsValue({
        vendor_id:v.id,
        vendor_name:v.name,
      });
    }
  },[vendor]);

  useEffect(()=>{
    // if(userdefine.length>0){
      // alert(JSON.stringify(userdefine));
    const u=userdefine;
    var u1:any[]=[];
    var u2:any[]=[];
    u.map((item:any)=>{
      u1.push({uid:item.uid,value:item.value});
      u2.push(''.concat(item.uname,':',item.vlabel==''?item.value:item.vlabel));
    });

    editorFormRef.current?.setRowData?.(rowno.toString(),{
      userdefine_id:JSON.stringify(u1),
      userdefine_name:u2.toString(),
    });
     
  // }
  },[userdefine]);

  //当组件选择商品时，更新表格并重载--
        useEffect(()=>{
           if(material.length>0){
           var x:any[]=editorFormRef.current?.getRowsData?.();
           // alert(JSON.stringify(x));
           if(x==undefined)
              x=[];
           material.map((item:any)=>{
              x?.push({rid:Math.random().toFixed(10),id:Math.random().toFixed(10).toString(),
                        material_id:item.id,material_code:item.code,material_name:item.name,
                        invstd:item.invstd,invstd2:item.invstd2,munit_name:item.munit_name,  
                        hassample:0,deliverdate:moment().format('YYYY-MM-DD'),quantity:1, dosample:0,
                        userdefine_id:'[]',vendor_id:'[]',pic:item.pic,
              });
           });
           // alert(JSON.stringify(x));
           setDataSource(x);
            
            mform_ref.current?.setFieldValue('editortable',x);
            mtable2_ref.current?.reloadAndRest?.();
        }
        },[material]);
  
  interface DataType{
      id:number,x_id:number,code:string,org_id:number,purchase_type_id:number,vendor_id:number,operater_id:number,
      status:number,state:number,memo:string,source_queryprice_mid:number,dep_name:string,
      purchasetype_name:string,vendor_name:string,operater_name:string,operate_time:string,addition:string,
   } 

   const columns:ProColumns<DataType>[]=[
    {dataIndex:'id',title:'id',hidden:true,search:false},{dataIndex:'code',title:'采购单号',width:180},
    {dataIndex:'addition',hidden:true,search:false},
    {dataIndex:'operate_time',title:'下单时间',valueType:'date',width:180},
    {dataIndex:'vendor_name',title:'供应商',width:260},
    {dataIndex:'dep_name',title:'部门',search:false,width:180},
    {dataIndex:'purchasetype_name',title:'采购类型',search:false,width:180},
    {dataIndex:'operater_name',title:'操作人',width:100},
    // {dataIndex:'state',title:'进度',search:false,
    //   render:(text:any)=>state2text(1,text),
    // },
     {dataIndex:'status',title:'状态',valueType:'select',width:80,
            valueEnum:{1:{text:'未审核'},5:{text:'已审核'},
            6:{text:'已弃审'},2:{text:'关闭'},3:{text:'删除'},9:{text:'全部'}}
        }, 
   ];

   interface DataType2{
    pic?:string,
    rid:number,id:number,mid:number,material_id:number,userdefine_id:string,userdefine_name:string,quantity:number,
    deliverdate:string,price:number,taxrate:number,total:number,netprice:number,tax:number,nettotal:number,
    memo:string,source_queryprice_id:number,
    material_code:string,material_name:string,invstd:string,invstd2:string,munit_name:string,
    source_type?:number,source_order_mid?:number,source_order_did?:number,
    quantity_current?:number,quantity_islock?:number,vendor_name?:string,source_did?:number,
   }

   const columns2:ProColumns<DataType2>[]=[
    {dataIndex:'pic',title:'图片' ,editable:false,width:80,
  //     render:(text)=>{
  //         var pic=text=="-"||text==undefined?"":"/basis_api/file/get?filename="+text;
  //         return <Image src={pic}  
  //                style={{width:50,height:50}} alt='无' />
  //    },
  //  },
        render:(text,record,index,k)=>{
                           var pic="/basis_api/file/get2?filename="+record.material_code;
                           return   <Image src={pic}  style={{width:50,height:50}} alt='无' />
      }},
      {dataIndex:'rid',title:'rid',editable:false,hidden:true},
      {dataIndex:'id',title:'ID',editable:false},
    // {dataIndex:'source_order_mid',title:'来源mid'},{dataIndex:'source_order_did',title:'来源did'},
    // {dataIndex:'material_id',title:'商品ID',editable:false},
    // {dataIndex:'userdefine_id',hidden:true,title:'自定义ID'},
    {dataIndex:'material_code',title:'SKU编码',editable:false},
   {dataIndex:'material_name',title:'商品名称',editable:false},
   {dataIndex:'invstd',title:'包装规格',editable:false},
  //  {dataIndex:'invstd2',title:'型号',editable:false},
  //  {dataIndex:'userdefine_name',title:'属性',editable:false},
  //  {title:'属性',editable:false,
  //   render:(text,record)=><QueryUserDefine setData={setUserDefine} 
  //                 objtype={1} dotype={1} id={record.material_id} setRowno={setRowno} rowno={record.rid} />
  //  },
   {dataIndex:'munit_name',title:'主单位',editable:false},
   {dataIndex:'price',title:'含税单价',valueType:'digit',
    fieldProps:(_,{rowIndex})=>{
      return {
         onChange:()=>{
            // alert(rowIndex);
            const rowdata=editorFormRef?.current?.getRowData?.(rowIndex);
            // alert(JSON.stringify(rowdata));
            const quantity=rowdata?.quantity==null?0:rowdata?.quantity;
            const price=rowdata?.price==null?0:rowdata?.price;
            const taxrate=rowdata?.taxrate==null?0:rowdata?.taxrate;
            editorFormRef.current?.setRowData?.(rowIndex,
               {total:quantity*price,
                 netprice:price/(1+taxrate/100),
                 nettotal:(price/(1+taxrate/100))*quantity,
               });
         },
      }
   }
   },
   {dataIndex:'taxrate',title:'税率%',valueType:'digit',
    fieldProps:(_,{rowIndex})=>{
      return {
         onChange:()=>{
            // alert(rowIndex);
            const rowdata=editorFormRef?.current?.getRowData?.(rowIndex);
            // alert(JSON.stringify(rowdata));
            const quantity=rowdata?.quantity==null?0:rowdata?.quantity;
            const price=rowdata?.price==null?0:rowdata?.price;
            const taxrate=rowdata?.taxrate==null?0:rowdata?.taxrate;
            editorFormRef.current?.setRowData?.(rowIndex,
                {total:quantity*price,
                 netprice:price/(1+taxrate/100),
                 nettotal:(price/(1+taxrate/100))*quantity,
               });
         },
      }
   }
   },
   {dataIndex:'quantity',title:'数量',valueType:'digit',
    fieldProps:(_,{rowIndex})=>{
      return {
         onChange:()=>{
            // alert(rowIndex);
            const rowdata=editorFormRef?.current?.getRowData?.(rowIndex);
            // alert(JSON.stringify(rowdata));
            const quantity=rowdata?.quantity==null?0:rowdata?.quantity;
            const price=rowdata?.price==null?0:rowdata?.price;
            const taxrate=rowdata?.taxrate==null?0:rowdata?.taxrate;
            editorFormRef.current?.setRowData?.(rowIndex,
                {total:quantity*price,
                 netprice:price/(1+taxrate/100),
                 nettotal:(price/(1+taxrate/100))*quantity,
               });
         },
      }
   }
   },
   {dataIndex:'total',title:'价税合计',valueType:'digit',},
   {dataIndex:'deliverdate',title:'交付日期',valueType:'date',
      // render:(text:any)=>moment(moment(text).toDate()).format('YYYY-MM-DD'),
   },
   {dataIndex:'quantity_current',title:'总现存量',editable:false},
   {dataIndex:'quantity_islock',title:'锁定量',editable:false},
  //  {dataIndex:'vendor_name',title:'供应商',editable:false},
   {dataIndex:'memo',title:'备注',width:300},
    //  {dataIndex:'source_did',title:'source_did',editable:false},
   
//  {
//     title:'操作',
//     fixed:'right',
//     valueType:'option',
//     width:80,
//     editable:false,
//     render:(text,record,_,action)=>[
//       //  <a key='edit2'
//       //     onClick={()=>{
//       //         alert(record.rid);
//       //        action?.startEditable?.(record.rid);}}
//       //  >
//       //      编辑
//       //  </a>,
//        <a  key='del2'
//            onClick={()=>{
//              var x:any[]=editorFormRef.current?.getRowsData?.();
//              //  alert(JSON.stringify(x));
//              setDataSource(x.filter((item)=>item.id!=record.id));
//              // alert(JSON.stringify(x.filter((item)=>item.id!=record.id)));
//              // mtable2_ref.current?.reloadAndRest?.();
//              mform_ref.current?.setFieldValue('editortable',x.filter((item)=>item.rid!=record.rid));
//            }}
//        >
//            删除
//        </a>,
//     ]
//  }
  ];

  //从销售生需求单
interface DataTypeSale{
// rid,x_id,sale_order_mid,org_id,custom_id,operate_time,sale_order_code,business_id,
// org_name,custom_name,business_name,sale_order_did,userdefine_id,userdefine_name,quantity,deliverdate,memo,
// mmaterial_id,mcode,minvstd,mname,mpic,mmunit_name,material_id,invstd,invstd2,pic,munit_name,quantity_rate, 
// quantity_require 
rid?:number,x_id?:number,sale_order_mid?:number,org_id?:number,custom_id?:number,operate_time?:string,
sale_order_code?:number,business_id?:number,org_name?:number,custom_name?:number,business_name?:number,
sale_order_did?:number,userdefine_id?:number,userdefine_name?:number,quantity?:number,deliverdate?:number,
memo?:number,mmaterial_id?:number,mcode?:number,minvstd?:number,mname?:number,mpic?:number,
mmunit_name?:number,material_id?:number,invstd?:number,invstd2?:number,pic?:number,munit_name?:number,
quantity_rate?:number, quantity_require?:number,code?:string, 
quantity_current?:number,quantity_islock?:number,
 
};

const columnsSale:ProColumns<DataTypeSale>[]=[
  {dataIndex:'mpic',title:'图片' ,editable:false,width:100,
  //     render:(text)=>{
  //         var pic=text=="-"||text==undefined?"":"/basis_api/file/get?filename="+text;
  //         return <Image src={pic}  
  //                style={{width:100,height:100}} alt='无' />
  //    },
  //  },
  render:(text,record,index,k)=>{
                         var pic="/basis_api/file/get2?filename="+record.mcode;
                         return   <Image src={pic}  style={{width:50,height:50}} alt='无' />
       }},
  // {dataIndex:'rid',title:'rid',editable:false,},{dataIndex:'sale_order_mid',title:'mid',editable:false,},
  // {dataIndex:'sale_order_did',title:'did',editable:false,},
  {dataIndex:'operate_time',title:'下单日期',valueType:'date',editable:false,},{dataIndex:'org_name',title:'部门',editable:false,},
  {dataIndex:'sale_order_code',title:'申报单号',editable:false,},{dataIndex:'custom_name',title:'店铺',editable:false,},
  {dataIndex:'business_name',title:'业务员',editable:false,},
  {dataIndex:'mcode',title:'主SKU',editable:false,},{dataIndex:'mname',title:'主名称',editable:false,},
  {dataIndex:'minvstd',title:'主包装规格',editable:false,},
  {dataIndex:'munit_name',title:'主单位',editable:false,},{dataIndex:'quantity',title:'申报数量',editable:false,},
  {dataIndex:'pic',title:'图片' ,editable:false,width:100,
  //     render:(text)=>{
  //         var pic=text=="-"||text==undefined?"":"/basis_api/file/get?filename="+text;
  //         return <Image src={pic}  
  //                style={{width:100,height:100}} alt='无' />
  //    },
  //  },
  render:(text,record,index,k)=>{
                         var pic="/basis_api/file/get2?filename="+record.code;
                         return   <Image src={pic}  style={{width:50,height:50}} alt='无' />
       }},
   {dataIndex:'code',title:'子SKU',editable:false,},{dataIndex:'name',title:'子名称',editable:false,},
   {dataIndex:'invstd',title:'子包装规格',editable:false,},
  {dataIndex:'munit_name',title:'子单位',editable:false,},
  {dataIndex:'quantity_rate',title:'换算率',editable:false,},
  {dataIndex:'quantity_require',title:'子需求数量',editable:false,},
  {dataIndex:'quantity_now',title:'本次下单数量',width:120 },
  {dataIndex:'quantity_current',title:'总现存量',width:120 ,editable:false,},
  {dataIndex:'quantity_islock',title:'锁定量',width:120,editable:false, },
  {
    title:'操作',
    fixed:'right',
    valueType:'option',
    width:80,
    editable:false,
    render:(text,record,_,action)=>[
       <a  key='del2'
           onClick={()=>{
             var x:any[]=editableRef_sale.current?.getRowsData?.();
             formRef_sale.current?.setFieldValue('editable_sale',x.filter((item)=>item.rid!=record.rid));
           }}
       >
           删除
       </a>,
    ]
 }

];

// x_id,id,material_id,quantity,quantity_done,status,
// operate_time,operater_id,source_mid,source_did,ispart,
// alloc_type,deliverdate,code,name,invstd,munit_name,pic,
// vendor_id,price,taxrate,begindate,enddate,vendor_name
interface DataTypeAlloc{
rid?:number,  
x_id?:number,id?:number,material_id?:number,quantity?:number,quantity_done?:number,status?:number,
operate_time?:string,operater_id?:number,source_mid?:number,source_did?:number,ispart?:number,
alloc_type?:number,deliverdate?:string,code?:string,name?:string,invstd?:string,munit_name?:string,pic?:string,
vendor_id?:number,price?:number,taxrate?:number,begindate?:number,enddate?:number,
vendor_name?:string,quantity_undone?:number,
quantity_current?:number,quantity_islock?:number,memo?:string,

};

const columnsAlloc:ProColumns<DataTypeAlloc>[]=[
  {dataIndex:'pic',title:'图片' ,editable:false,width:100,
  //     render:(text)=>{
  //         var pic=text=="-"||text==undefined?"":"/basis_api/file/get?filename="+text;
  //         return <Image src={pic}  
  //                style={{width:100,height:100}} alt='无' />
  //    },
  //  },
      render:(text,record,index,k)=>{
                           var pic="/basis_api/file/get2?filename="+record.code;
                           return   <Image src={pic}  style={{width:50,height:50}} alt='无' />
  }},
  // {dataIndex:'rid',title:'rid',editable:false},
   {dataIndex:'id',title:'id',editable:false,hidden:true},
  //  {dataIndex:'material_id',title:'material_id',editable:false}, 
   {dataIndex:'code',title:'SKU编码',editable:false,width:'6%'},
    {dataIndex:'name',title:'商品名称',editable:false,width:'10%'}, 
    {dataIndex:'invstd',title:'包装规格',editable:false,width:'10%'},
     {dataIndex:'munit_name',title:'单位',editable:false,width:80}, {dataIndex:'quantity',title:'需求总数',editable:false},
       {dataIndex:'quantity_done',title:'已下单数',editable:false},
       {dataIndex:'quantity_undone',title:'未下单数',editable:false,
        renderText(text, record, index, action) {
              return (record.quantity?record.quantity:0)-(record.quantity_done?record.quantity_done:0)
        },
       },
       {dataIndex:'quantity_now',title:'本次下单数',valueType:'digit',width:100},
       
       {dataIndex:'deliverdate',title:'需求日期',valueType:'date',width:160},
       {dataIndex:'quantity_current',title:'总现存量',valueType:'digit',width:100,editable:false},
       {dataIndex:'quantity_islock',title:'锁定量',valueType:'digit',width:100,editable:false},
        {dataIndex:'vendor_name',title:'供应商',editable:false},
 {dataIndex:'price',title:'含税单价',editable:false}, 
//  {dataIndex:'taxrate',title:'税率%',editable:false},
//   {dataIndex:'begindate',title:'定价生效日期',editable:false,valueType:'date',},
 {dataIndex:'memo',title:'备注',width:200,},
  //  {dataIndex:'source_did',search:false,title:'source_did'},
  {
    title:'操作',
    fixed:'right',
    valueType:'option',
    width:80,
    editable:false,
    render:(text,record,_,action)=>[
      //  <a key='edit2'
      //     onClick={()=>{
      //         alert(record.rid);
      //        action?.startEditable?.(record.rid);}}
      //  >
      //      编辑
      //  </a>,
       <a  key='close'
           onClick={async ()=>{
             var x:any[]=editableRef_alloc.current?.getRowsData?.();
             //  alert(JSON.stringify(x));
            //  setDataSource(x.filter((item)=>item.id!=record.id));
             // alert(JSON.stringify(x.filter((item)=>item.id!=record.id)));
             // mtable2_ref.current?.reloadAndRest?.();
             formRef_alloc.current?.setFieldValue('editable_alloc',x.filter((item)=>item.rid!=record.rid));
             
             //将需求来源关闭 2025-07-23
            //  source,x_id,operater_id,etype,JSON.stringify(fdata)
             const y=await s_purchase_updateInfo({source:'close_require',x_id:1,
                           operater_id:initialState?.currentUser?.userid,etype:0,fdata:{id:record.source_did}});
           }}
       >
           关闭
       </a>,
    ]
 },
   ];

   interface DataPrint{
      material_code?:string,material_name?:string,invstd?:string,munit_name?:string,
      quantity?:number,pic?:string,deliverdate?:string,price?:number,total?:number,memo?:string,
   };

   const columnPrint:ProColumns<DataPrint>[]=[
     {dataIndex:'pic',title:'图片' ,editable:false,width:100,
    //   render:(text)=>{
    //       var pic=text=="-"||text==undefined?"":"/basis_api/file/get?filename="+text;
    //       return <Image src={pic}  
    //              style={{width:80,height:80}} alt='无' />
    //  },
    // },
         render:(text,record,index,k)=>{
                         var pic="/basis_api/file/get2?filename="+record.material_code;
                         return   <Image src={pic}  style={{width:50,height:50}} alt='无' />
       }},
    {dataIndex:'material_code',title:'SKU编码',width:120},
    {dataIndex:'material_name',title:'商品名称',width:200},
    {dataIndex:'invstd',title:'包装规格',width:200},
    {dataIndex:'munit_name',title:'单位',width:80},
    {dataIndex:'quantity',title:'采购数量',width:80},
    {dataIndex:'price',title:'平均单价',width:80},
    {dataIndex:'total',title:'金额',width:80},
    {dataIndex:'deliverdate',title:'需求日期',width:100,valueType:'date'},
    // {dataIndex:'memo',title:'备注',width:120},
   ];

function closeModal(){
      setOpen(false);
      setEtype(1);
      // setVouchCode(null);
   }

   function add(){
    setEtype(1);
    setOpen(true);
   }

   async function edit(){
    if(selectedRecord.length==0)
      message.warning('请先选择要编辑的行');
    else if(selectedRecord[0].status==2||selectedRecord[0].status==3||selectedRecord[0].status==5)
      message.warning('不能编辑已审核、已关闭或已删除的单据。请选弃审或恢复');
    else{
        setEtype(0);
        // 获取对应的ID明细数据
        const x=await s_getcommontableinfo({x_id:1,source:'v_order_detail',id:0,fdata:{mid:selectedRecord[0].id}});
          // alert(JSON.stringify(x.data[0]));
        if(x.data[0].length>0){
          setDataSource(x.data[0]);
           
          setVouchCode(selectedRecord[0].code);
          setOpen(true);
        }
    };
   }

     function saveModal(otype:number){

      
      const x=editorFormRef?.current?.getRowsData?.();
      x?.map((item,index)=>{
        mtable2_ref.current?.saveEditable?.(index);
      });
     var y=x?.filter((item:any)=>item.quantity==undefined||item.quantity=='null'||item.price==undefined||item.price=='null'
                                  ||item.taxrate==undefined||item.taxrate=='null');
    //  alert(JSON.stringify(y.length));
     if(y&&y.length>0)
        message.warning('采购数量、单价、税率、金额都不能为空');
      else{
         mform_ref.current?.submit();
          setOtype(otype);
      };
    //  setEtype(1);
    //  mform_ref.current?.submit();
   };

   async function saveModal2(){
        const fdata2=mform_ref.current?.getFieldsValue();
        const t1=fdata2.editortable;
        const t2=t1.map((item:any)=>({...item,deliverdate:moment(moment(item.deliverdate).toDate()).format('YYYY-MM-DD')}));
        const fdata={...fdata2,editortable:t2,addition};

        //  alert(JSON.stringify(t2)) ;
        // source,x_id,operater_id,etype,fdata
        const x=await s_updateInfo({x_id:1,source:'purchase_order',operater_id:initialState?.currentUser?.userid,etype,fdata});
        if(x.success){
          message.success('保存成功');
          setEtype(1);
          setSelectedRecord([]);
          mtable_ref.current?.reloadAndRest?.();
          setOpen(false);
        }else
          message.error('保存失败，请联系管理员');

        

   }

   //  操作询价单/关闭/删除/恢复
   async function operateInfo(n:number){
    // source,x_id,operater_id,otype,id
    if(selectedRecord.length==0)
       message.warning('请选择要操作的行');
     else if(n==5&&selectedRecord[0].status==5)
          message.warning('此单据已审核，请不要重复操作');
     else if(n==6&&selectedRecord[0].status!=5)
          message.warning('此单据未审核，不能弃审');
    else{
     const x=await s_operateInfo({x_id:1,source:'order_main',operater_id:initialState?.currentUser?.userid,otype:n,id:selectedRecord[0].id});
     if(x.success){
       message.success('操作成功');
       mtable_ref.current?.reloadAndRest?.();
     }else
       message.error('操作错误，请联系管理员。');
    }
 };

  // 全部开始编辑，置表格为编辑状态
  function quote(){
    //用一个循环
    const x:any[]=editorFormRef.current?.getRowsData?.();
    if(x!=undefined&&x.length>0)
      x.map((item:any,index)=>{
          mtable2_ref.current?.startEditable?.(index);
       }
    );
    else
      message.warning('没有任何修改');
  }

  //获取价格
  async function getPrice(){
    const tdata=mform_ref.current?.getFieldValue('editortable');
    const ven_id=mform_ref.current?.getFieldValue('vendor_id');
    if(tdata==undefined||ven_id==undefined||tdata.length==0||ven_id=='')
      message.warning('请先选择供应商和商品明细');
    else{
      var x:any=[];
      x=await s_getcommontableinfo({source:'v_priceschedule2',x_id:1,id:0,fdata:{vendor_id:ven_id}});
      alert(JSON.stringify(x));
      const tableData:any[]=editorFormRef?.current?.getRowsData?.();
      tableData.map((item:any,rowIndex:any)=>{
        const rowData=editorFormRef.current?.getRowData?.(rowIndex);
        x.data[0].map((item:any)=>{
            // 当前价格仅匹配供应商+商品ID,后续应考虑自定义项
           if(rowData.material_id==item.material_id){
                editorFormRef.current?.setRowData?.(rowIndex,
                  {price:item.price,
                   taxrate:item.taxrate,
                   netprice:item.netprice,
                   total:rowData.quantity*item.price,
                   nettotal:rowData.quantity*item.netprice,
                   tax:rowData.qnantity*item.taxrate,
                  });  
           }
        });
      });
    }
  };

  //打开销售生单界面
  function querySale(){
    setOpenSale(true);
  };

  function exitSale(){
     setOpenSale(false);
  };

 

  //查询销售订单的材料明细
  async function querySaleDetail(){
     const custom_id=formRef_sale.current?.getFieldValue('custom_id');
     const business_id=formRef_sale.current?.getFieldValue('business_id');
     const operater_id=formRef_sale.current?.getFieldValue('operater_id');
     const mmaterial_name=formRef_sale.current?.getFieldValue('mmaterial_name');
     const material_name=formRef_sale.current?.getFieldValue('material_name');
     const sale_order_code=formRef_sale.current?.getFieldValue('sale_order_code');
     var begindate=formRef_sale.current?.getFieldValue('begindate');
     if(begindate)
          begindate=begindate?moment(moment(begindate).toDate()).format('YYYY-MM-DD'):null; 
     var enddate=formRef_sale.current?.getFieldValue('enddate');
     if(enddate)
         enddate=enddate?moment(moment(enddate).toDate()).format('YYYY-MM-DD'):null; 
     
     const x=await s_getcommontableinfo({source:'v_purchase_from_saleorder',x_id:1,id:0,cate_id:[],
                    fdata:{x_id:1,custom_id,business_id,mmaterial_name,material_name,
                          begindate,enddate,sale_order_code,operater_id} });

    //  alert(JSON.stringify(x.data[0]));

     formRef_sale.current?.setFieldValue('editable_sale',x.data[0]);
  };

  //编辑销售单材料
  function editSale(){
      const fdata=formRef_sale.current?.getFieldValue('editable_sale');
    fdata.map((item:any)=>{
      actionRef_sale.current?.startEditable(item.rid);
    });
  };

  //加入到采购单
   function addToPurchase(){
      const sale=saleRecords.map((item:any)=>{
           return {
              rid:item.rid,
              pic:item.pic,
              material_id:item.material_id,
              quantity:item.quantity_now,
              dotype:2,
              // source_order_mid:item.sale_order_mid,
              // source_order_did:item.sale_order_did,
              source_did:item.source_did,
              material_code:item.code,
              material_name:item.name,
              invstd:item.invstd,
              invstd2:item.invstd2,
              munit_name:item.munit_name,
              price:item.price,
              taxrate:item.taxrate,
              quantity_current:item.quantity_current,
              quantity_islock:item.quantity_islock,
              vendor_name:item.vendor_name,
           };
      });
       
      //  alert(JSON.stringify(sale));
      
      var x=mform_ref.current?.getFieldValue('editortable');
      x=x?x:[];
      // alert(JSON.stringify(x));
      mform_ref.current?.setFieldValue('editortable',[...sale,...x]);
  };

  function exitAlloc(){
    setOpenAlloc(false);
  };

  //加入到采购单
   function addAllocToPurchase(){
      const alloc=allocRecords.map((item:any)=>{
           return {
              rid:item.rid,
              pic:item.pic,
              material_id:item.material_id,
              quantity:item.quantity_now,
              source_type:1,
              source_order_mid:item.source_mid,
              source_order_did:item.source_did,
              material_code:item.code,
              material_name:item.name,
              invstd:item.invstd,
              invstd2:item.invstd2,
              munit_name:item.munit_name,
              price:item.price,
              taxrate:item.taxrate,
              total:item.price*item.taxrate,
              deliverdate:item.deliverdate,
              quantity_current:item.quantity_current,
              quantity_islock:item.quantity_islock,
              vendor_name:item.vendor_name,
              //2025-06-09
              dotype:2,
              source_did:item.source_did,
              memo:item.memo,
           };
      });
       
      //  alert(JSON.stringify(sale));
     
      var x=mform_ref.current?.getFieldValue('editortable');
      x=x?x:[];
      // alert(JSON.stringify(x));
      mform_ref.current?.setFieldValue('editortable',[...alloc,...x]);
  };

  //查询采购分配材料明细
  async function queryAllocDetail(){
     const vendor_id=formRef_alloc.current?.getFieldValue('vendor_id');
     const code=formRef_alloc.current?.getFieldValue('code');
     const name=formRef_alloc.current?.getFieldValue('name');
     
     //清空已选择项
     setAllocRecords([]);
     setSelectedLineKeys2([]);
    //  const x=await s_getcommontableinfo({source:'v_purchase_from_alloc',x_id:1,id:0,cate_id:[],
    //                 fdata:{vendor_id,code,name} });
    const x=await s_getPurchaseInfo({x_id:1,source:'v_purchase_from_produce',
                                        fdata:{vendor_id,code,name}});

      // alert(JSON.stringify(x.data[0]));

     formRef_alloc.current?.setFieldValue('editable_alloc',x.data[0]);
  };

  function queryAlloc(){
       setOpenAlloc(true);
  };
  
  function editAlloc(){
      const fdata=formRef_alloc.current?.getFieldValue('editable_alloc');
      fdata.map((Item:any)=>{
         actionRef_alloc.current?.startEditable(Item.rid);
      });
  };

//printOrder 合并打印SKU  2025-06-08
function printOrder(){
     if(selectedRecord&&selectedRecord.length==0)
        message.warning('请先选择要打印的采购单');
      else
        setOpenPrint(true);
};

  //  主界面======================================================================================================
  return <>
     <ProCard title='采购单管理' style={{height:'85vh',overflow:'auto'}}
       extra={<Space>
           <Button onClick={()=>add()}>新增</Button>
           <Button onClick={()=>edit()}>编辑</Button>
           {/* <Button onClick={()=>operateInfo(12)}>下达</Button>
           <Button onClick={()=>operateInfo(19)}>取消下达</Button> */}
           <Button onClick={()=>operateInfo(5)}>审核</Button>
           <Button onClick={()=>operateInfo(6)}>取消审核</Button>
           <Button onClick={()=>printOrder()}>打印</Button>
           <Button onClick={()=>operateInfo(2)}>关闭</Button>
           <Button onClick={()=>operateInfo(3)}>删除</Button>
           <Button onClick={()=>operateInfo(0)}>恢复</Button>
       </Space>}
     >
      {/* {JSON.stringify(selectedRecord)} */}
      <ProTable<DataType>
        options={false}
        actionRef={mtable_ref}
        columns={columns}
        rowKey='id'
        search={{span:4}}
        // request={async ()=>{
        //   // alert(11);
        //   const x=await s_getTableInfo({source:'v_order_main',x_id:1,id:0});
        //   // alert(JSON.stringify(x.data));
        //   return {
        //     data:x.data,
        //     success:true,
        //   }
        // }}
        request={async (param)=>{
                            const x=await s_getPurchaseInfo({source:'v_order_main',x_id:1,
                                          fdata:{id:0,param}});
                             setTotal(x.data[0][0].count);
                              return{
                                    data:x.data[1],
                                    success:true,
                                  }
                               }}
        rowSelection={{
          type:'radio',
          selectedRowKeys:selectedLineKeys,
          async onChange(selectedRowKeys, selectedRows, info) {
              setSelectedRecord(selectedRows);
              setSelectedLineKeys(selectedRowKeys);
              const x=await s_getcommontableinfo({x_id:1,source:'v_order_detail',id:0,
                         fdata:{mid:selectedRows.length>0?selectedRows[0].id:0}});
                // alert(JSON.stringify(x.data[0]));
            if(x.data[0].length>0){
              setDataSource(x.data[0]); 
              setDataPrint(x.data[1]);
               
            }else{
              setDataSource([]);
              setDataPrint([]);
            };
          },
        }} 
 onRow={(record)=>{
            return {
              onClick:async ()=>{
                const k=record.id;
                // if(selectedKeys.includes(k) )
                //      setSelectedKeys(selectedKeys.filter(item=>item.id!=k));
                // else
                     setSelectedLineKeys([k]);
                     setSelectedRecord([record]);
                     const x=await s_getcommontableinfo({x_id:1,source:'v_order_detail',id:0,
                          fdata:{mid:k?k:0}});
                // alert(JSON.stringify(x.data[0]));
            if(x.data[0].length>0){
              setDataSource(x.data[0]); 
              setDataPrint(x.data[1]);
            }else{
              setDataSource([]);
              setDataPrint([]);
            };
              },
            }
           }}
        scroll={{y:'25vh'}}
           pagination={{
                 showQuickJumper:true,
                 showSizeChanger:true,
                 defaultPageSize:10,
                 defaultCurrent:1,
                 total,
                  }}
      />
      <ProTable<DataType2>
        // actionRef={mtable_ref}
        columns={columns2}
        rowKey='id'
        // request={async ()=>{
        //   // alert(11);
        //   const x=await s_getTableInfo({source:'v_order_main',x_id:1,id:0});
        //   // alert(JSON.stringify(x.data));
        //   return {
        //     data:x.data,
        //     success:true,
        //   }
        // }}
        // rowSelection={{
        //   type:'radio',
        //   async onChange(selectedRowKeys, selectedRows:any, info) {
        //       setSelectedRecord(selectedRows);
        //       const x=await s_getcommontableinfo({x_id:1,source:'v_order_detail',id:0,fdata:{mid:selectedRows[0].id}});
        //       // alert(JSON.stringify(x.data[0]));
        //     if(x.data[0].length>0){
        //       setDataSource(x.data[0]); 
        //     };
        //   },
        // }} 
        scroll={{y:'25vh'}} 
        options={false}
        dataSource={dataSource}
        search={false}
      />
     </ProCard>

     {/* 订单编辑窗体----------------------------------------------------------------------------------------------------- */}
     <Modal open={open} closable destroyOnClose okButtonProps={{hidden:true}} cancelButtonProps={{hidden:true}}
        onCancel={()=>closeModal()} onClose={()=>closeModal()} width='90%' style={{top:10}} 
     >
      <ProCard title='采购单明细' style={{height:900}}
         extra={<Space>
          {/* <Button onClick={()=>querySale()}>查询申报单</Button> */}
          <Button onClick={()=>queryAlloc()}>查询申报采购需求</Button>
          {/* <QueryVendor setData={setVendor} x_id={1} disabled={1} type='radio' /> */}
          <QueryMaterial2 setData={setMaterial} type='checkbox' x_id={1}/>
          {/* <Button onClick={()=>getPrice()}>获取价格</Button> */}
          <Button onClick={()=>quote()}>开始编辑</Button>
          <Button onClick={()=>saveModal(1)}>保存</Button>
          {/* <Button onClick={()=>saveModal(2)}>保存并下达</Button> */}
          {/* <Button onClick={()=>operateInfo(12)}>下达</Button>
          <Button onClick={()=>operateInfo(19)}>取消下达</Button> */}
          <Button onClick={()=>closeModal()}>关闭</Button>
         </Space>}
      >
     {/* 表头 id,x_id,code,org_id,purchase_type_id,vendor_id,operater_id,
     status,state,memo,source_queryprice_mid,dep_name,
     purchasetype_name,vendor_name,operater_name */}
     {/* 表体 rid,id,mid,material_id,userdefine_id,userdefine_name,quantity,
     deliverdate,price,taxrate,total,netprice,tax,nettotal,memo,source_queryprice_id,
     material_code,material_name,invstd,invstd2,munit_name */}
       <ProForm submitter={false} formRef={mform_ref}
         labelAlign="left" layout="horizontal" labelCol={{offset:0,span:5}}
          onFinish={()=>saveModal2()}
          initialValues={etype==1?{
                       state:1,status:0,operater_id:initialState?.currentUser?.userid,
                     }:{
                       ...selectedRecord[0],
                       editortable:dataSource,
                     }}
       >
         <Row gutter={8}>
          <Col span={8}>
             <ProFormText name='code' label='单据编码' width={300}
              //  rules={[{required:true,message:'此为必填项'}]}
               fieldProps={{
                onChange:(e:any)=>{
                   setVouchCode(e.target.value);
                // mform_ref.current?.setFieldValue('addition',e.target.value);
               }
               }}
             />
             <ProFormSelect name='org_id' label='部门' width={300}
             request={async ()=>{
              var x:any=await getSelection({ source: 'base_organization', x_id: 1 });
              var x2=x.data.map((item:any)=>({value:item.id,label:item.name}));
              return x2;
              }}
             />
            
          </Col>
          <Col span={8}>
              
                  <ProFormSelect name='vendor_id' label='供应商' width={300}
                      rules={[{required:true,message:'必填项'}]}
                      showSearch
                      request={async ()=>{
                      const x=await s_getSelectData({x_id:1,source:'v_vendor'});
                          return x.data;}}
                  />
                  {/* <QueryVendor setData={setVendor} x_id={1} disabled={1} type='radio' /> */}
              
             <ProFormSelect name='purchase_type_id' label='采购类型' width={300}
                request={async ()=>{
                  var x:any=await getSelection({ source: 'base_purchasetype', x_id: 1 });
                  var x2=x.data.map((item:any)=>({value:item.id,label:item.name}));
                  return x2;
                  }}
             />
             {/* {JSON.stringify(vouchCode)} */}
             {/* <Addition source_xid={1} setData={setAddition} type={2}
                            fdata={{source_table:'addition_order_main',
                                  source_code:vouchCode,
                                  source_field:'addition',
                                  source_id:selectedRecord.length==0?0:selectedRecord[0].id,
                                  source_value:selectedRecord.length==0||selectedRecord[0].addition==null||selectedRecord[0].addition==''?[]:selectedRecord[0].addition}}
                         /> */}
          </Col>
          <Col span={8}>
          <ProFormSelect name='state' label='进度' width={300} 
          rules={[{required:true,message:'此为必填项'}]}
          options={[{value:1,label:'未下达'},{value:2,label:'已下达'},{value:3,label:'供方已确认'},{value:4,label:'供方已拒绝'},
            {value:5,label:'已确认'},{value:6,label:'已拒绝'},{value:7,label:'撤销确认'},{value:8,label:'供方撤销确认'},
            {value:9,label:'撤销下达'},{value:10,label:'未提交'},{value:11,label:'已提交'},{value:12,label:'撤销提交'},
            {value:13,label:'已核价'},{value:14,label:'撤销核价'}
       ]}
          />
         <ProFormRadio.Group name='status' label='状态' width={300}
         rules={[{required:true,message:'此为必填项'}]}
              options={[{value:0,label:'未审核'},{value:2,label:'关闭'},
                      {value:5,label:'已审核'},{value:6,label:'弃审'},
                      {value:3,label:'删除'}]}
         />
          
          </Col>
         </Row>
         <Row gutter={8}>
            <Col span={8}>
                  <ProFormSelect name='operater_id' label='操作人' width={300}
                      rules={[{required:true,message:'此为必填项'}]}
                       request={async ()=>{
                       var x:any=await getSelection({ source: 'base_person', x_id: 1 });
                       var x2=x.data.map((item:any)=>({value:item.id,label:item.name}));
                       return x2;
                   }}
             />
            </Col>
            <Col span={16}>
                 <ProFormText name='memo' label='备注' labelCol={{offset:0,span:3}} />
            </Col>
         </Row>
         <ProFormText name='id' label='ID' hidden/>
         {/* <ProFormText name='vendor_id' hidden /> */}

             <EditableProTable<DataType2>
                       rowKey='rid'
                       name='editortable'
                       actionRef={mtable2_ref}
                       editableFormRef={editorFormRef}
                       onChange={(data:any)=>setDataSource(data)}
                       columns={columns2}
                       editable = {{                       // defaultDom = {save,cancel,delete} 可以酌情添加和使用
                                 actionRender: (row, config, defaultDom) => [
                                   defaultDom.save,
                                 //   defaultDom.cancel,
                                 ],
                                 type:'multiple'
                               }}
                      recordCreatorProps={false}
                      scroll={{y:520}}
                            />
       </ProForm>
      </ProCard>
     
     </Modal>

     {/* 销售订单的材料查询界面---------------------------------------------------------------------------- */}
      <Modal open={openSale} closable destroyOnClose okButtonProps={{hidden:true}} cancelButtonProps={{hidden:true}}
        onCancel={()=>exitSale()} onClose={()=>exitSale()} width='90%' style={{top:10}} 
     >
      <ProCard title='销售单材料查询界面' style={{height:900}}
         extra={<Space>
          <Button onClick={()=>editSale()}>开始编辑</Button>
          <Button onClick={()=>addToPurchase()}>加入到采购单</Button>
         
          {/* <Button onClick={()=>operateInfo(12)}>下达</Button>
          <Button onClick={()=>operateInfo(19)}>取消下达</Button> */}
          <Button onClick={()=>exitSale()}>关闭</Button>
         </Space>}
      >
     {/* 表头 id,x_id,code,org_id,purchase_type_id,vendor_id,operater_id,
     status,state,memo,source_queryprice_mid,dep_name,
     purchasetype_name,vendor_name,operater_name */}
     {/* 表体 rid,id,mid,material_id,userdefine_id,userdefine_name,quantity,
     deliverdate,price,taxrate,total,netprice,tax,nettotal,memo,source_queryprice_id,
     material_code,material_name,invstd,invstd2,munit_name */}
       <ProForm submitter={false} formRef={formRef_sale}
         labelAlign="left" layout="horizontal" labelCol={{offset:0,span:5}}
           
       >
         <Row gutter={8}>
          <Col span={5}>
             <ProFormSelect name='custom_id' label='店铺' width={300}
                showSearch
                 request={async ()=>{
                        const x=await s_getSelectData({x_id:1,source:'v_custom'});
                         return x.data;
                         }}
                        /> 
             <ProFormSelect name='business_id' label='业务员' width={300}
                  showSearch
                    request={async ()=>{
                     const x=await s_getSelectData({x_id:1,source:'v_businesser'});
                      return x.data;
                      }}
              />
         </Col>
         <Col span={5}>
              <ProFormText name='sale_order_code' label='申报单号' width={200} />
              <ProFormSelect name='operater_id' label='制单人' width={200} 
                 showSearch
                    request={async ()=>{
                     const x=await s_getSelectData({x_id:1,source:'base_person'});
                      return x.data;
                      }}
              />
          </Col>
          <Col span={5}>
              <ProFormText name='mmaterial_name' label='主SKU名称' width={200} />
              <ProFormText name='material_name' label='子SKU名称' width={200} />
          </Col>
          <Col span={5}>
               
              <ProFormDatePicker name='begindate' label='开始日期' width={200} />
              <ProFormDatePicker name='enddate' label='截止日期' width={200} />
          </Col>
          <Col span={4}>
              <Button onClick={()=>querySaleDetail()}>开始查询</Button>
          </Col>
         </Row>
         <ProCard style={{height:700,overflow:'auto'}}>
              <EditableProTable<DataTypeSale>
                               rowKey='rid'
                               name='editable_sale'
                               actionRef={actionRef_sale}
                               editableFormRef={editableRef_sale}
                              //  value={dataSource}
                               onChange={(data:any)=>setDataSource(data)}
                               columns={columnsSale}
                               editable = {{                       // defaultDom = {save,cancel,delete} 可以酌情添加和使用
                                 actionRender: (row, config, defaultDom) => [
                                  //  defaultDom.save,
                                 //   defaultDom.cancel,
                                 ],
                                 type:'multiple'
                               }}
                               recordCreatorProps={false}
                               scroll={{y:500}}
                               rowSelection={{
                                  type:'checkbox',
                                  onChange(selectedRowKeys, selectedRows:any, info) {
                                    setSaleRecords(selectedRows);
                                  },
                               }}
                            />
          </ProCard>
       </ProForm>
      </ProCard>
     
     </Modal>

     {/* 按采购分配------------------------------------------------------------------------- */}
    <Modal open={openAlloc} closable destroyOnClose okButtonProps={{hidden:true}} cancelButtonProps={{hidden:true}}
        onCancel={()=>exitAlloc()} onClose={()=>exitAlloc()} width='95%' style={{top:10}} 
       >
      <ProCard title='采购分配查询' style={{height:900}}
         extra={<Space>
          <Button onClick={()=>editAlloc()}>开始编辑</Button>
          <Button onClick={()=>addAllocToPurchase()}>加入到采购单</Button>
         
          {/* <Button onClick={()=>operateInfo(12)}>下达</Button>
          <Button onClick={()=>operateInfo(19)}>取消下达</Button> */}
          <Button onClick={()=>exitAlloc()}>关闭</Button>
         </Space>}
      >
       <ProForm submitter={false} formRef={formRef_alloc}
         labelAlign="left" layout="horizontal" labelCol={{offset:0,span:5}}
       >
         <Row gutter={8}>
          <Col span={5}>
              <ProFormSelect name='vendor_id' label='供应商' width={200} 
                  showSearch
                    request={async ()=>{
                    const x=await s_getSelectData({x_id:1,source:'v_vendor'});
                      return x.data;
                      }}
              />
          </Col>
          <Col span={5}>
              <ProFormText name='code' label='SKU编码' width={200} />
          </Col>
          <Col span={5}>
              <ProFormText name='name' label='SKU名称' width={200} />
          </Col>
          <Col span={4}>
              <Button onClick={()=>queryAllocDetail()}>+开始查询</Button>
          </Col>
         </Row>
         <ProCard style={{height:'80vh',overflow:'auto'}}>
              <EditableProTable<DataTypeAlloc>
                               rowKey='rid'
                               name='editable_alloc'
                               actionRef={actionRef_alloc}
                               editableFormRef={editableRef_alloc}
                              //  value={dataSource}
                               onChange={(data:any)=>setDataSource(data)}
                               columns={columnsAlloc}
                               editable = {{                       // defaultDom = {save,cancel,delete} 可以酌情添加和使用
                                 actionRender: (row, config, defaultDom) => [
                                  //  defaultDom.save,
                                 //   defaultDom.cancel,
                                 ],
                                 type:'multiple'
                               }}
                               recordCreatorProps={false}
                               scroll={{y:'65vh'}}
                               rowSelection={{
                                  type:'checkbox',
                                  selectedRowKeys:selectedLineKeys2,
                                  onChange(selectedRowKeys, selectedRows:any, info) {
                                    setAllocRecords(selectedRows);
                                    setSelectedLineKeys2(selectedRowKeys);
                                  },
                               }}
      onRow={(record)=>{
            return {
              onClick:()=>{
                const k=record.rid;
                // if(selectedKeys.includes(k) )
                //      setSelectedKeys(selectedKeys.filter(item=>item.id!=k));
                // else
                  if(k&&selectedLineKeys2.includes(k)){
                      setSelectedLineKeys2( selectedLineKeys2.filter(item=>item!=k));
                      setAllocRecords( allocRecords.filter(item=>item.rid!=k) );
                      // alert('1--------'+JSON.stringify(allocRecords));
                  }else{
                     setSelectedLineKeys2([...selectedLineKeys2,k]);
                     setAllocRecords([...allocRecords,record]);
                    //  alert('2--------'+JSON.stringify(allocRecords));
                  };
              },
            }
           }}
                            />
          </ProCard>
       </ProForm>
      </ProCard>
     
     </Modal>

     <Modal open={openPrint} closable destroyOnClose okButtonProps={{hidden:true}} cancelButtonProps={{hidden:true}}
        onCancel={()=>setOpenPrint(false)} onClose={()=>setOpenPrint(false)} width='80%' style={{top:10}} 
       >
          <ProCard style={{height:'80vh',overflow:'auto'}}>
           <Typography.Title style={{marginTop:30,textAlign:'center'}}>浦江华磊工贸有限公司采购单</Typography.Title>
           <Typography.Text style={{fontSize:26,textAlign:'center',display:'flex',justifyContent:'center',margin:20}}>
            供应商 : {selectedRecord.length>0?selectedRecord[0].vendor_name:''}---采购单号：{selectedRecord.length>0?selectedRecord[0].code:''}</Typography.Text>
             <ProTable<DataPrint>
                 options={false}
                 search={false}
                 columns={columnPrint}
                 dataSource={dataPrint}
                 bordered
              />
           </ProCard>
           
       </Modal>
  </>;
}

export default App;